/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class CartModifyItem
    {
    
        private String actionField;

        private String cartItemIdField;

        private Decimal? quantityField;


        /// <summary>
        /// Gets and sets the Action property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Action")]
        public String Action
        {
            get { return this.actionField ; }
            set { this.actionField= value; }
        }



        /// <summary>
        /// Sets the Action property
        /// </summary>
        /// <param name="action">Action property</param>
        /// <returns>this instance</returns>
        public CartModifyItem WithAction(String action)
        {
            this.actionField = action;
            return this;
        }



        /// <summary>
        /// Checks if Action property is set
        /// </summary>
        /// <returns>true if Action property is set</returns>
        public Boolean IsSetAction()
        {
            return this.actionField != null;

        }


        /// <summary>
        /// Gets and sets the CartItemId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "CartItemId")]
        public String CartItemId
        {
            get { return this.cartItemIdField ; }
            set { this.cartItemIdField= value; }
        }



        /// <summary>
        /// Sets the CartItemId property
        /// </summary>
        /// <param name="cartItemId">CartItemId property</param>
        /// <returns>this instance</returns>
        public CartModifyItem WithCartItemId(String cartItemId)
        {
            this.cartItemIdField = cartItemId;
            return this;
        }



        /// <summary>
        /// Checks if CartItemId property is set
        /// </summary>
        /// <returns>true if CartItemId property is set</returns>
        public Boolean IsSetCartItemId()
        {
            return  this.cartItemIdField != null;

        }


        /// <summary>
        /// Gets and sets the Quantity property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Quantity")]
        public Decimal Quantity
        {
            get { return this.quantityField.GetValueOrDefault() ; }
            set { this.quantityField= value; }
        }



        /// <summary>
        /// Sets the Quantity property
        /// </summary>
        /// <param name="quantity">Quantity property</param>
        /// <returns>this instance</returns>
        public CartModifyItem WithQuantity(Decimal quantity)
        {
            this.quantityField = quantity;
            return this;
        }



        /// <summary>
        /// Checks if Quantity property is set
        /// </summary>
        /// <returns>true if Quantity property is set</returns>
        public Boolean IsSetQuantity()
        {
            return  this.quantityField != null;

        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetAction()) {
                xml.Append("<Action>");
                xml.Append(this.Action);
                xml.Append("</Action>");
            }
            if (IsSetCartItemId()) {
                xml.Append("<CartItemId>");
                xml.Append(EscapeXML(this.CartItemId));
                xml.Append("</CartItemId>");
            }
            if (IsSetQuantity()) {
                xml.Append("<Quantity>");
                xml.Append(this.Quantity);
                xml.Append("</Quantity>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}